<template>
  <div>
    <!-- 权限点数据展示 -->
    <el-tree
      ref="tree"
      :data="permissionList"
      :props="{ label: 'name' }"
      show-checkbox
      default-expand-all
      check-strictly
      node-key="id"
      :default-checked-keys="defaultPermIds"
    />

    <el-row class="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button size="small" @click="cancelButton">取 消</el-button>
        <el-button size="small" type="primary" @click="setRolesBtn">确 定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'AssignPermission',
  props: {
    // 全部权限点-列表数据(树形结构)
    permissionList: {
      type: Array,
      default: _ => []
    },
    // 默认权限点->默认选中的
    defaultPermIds: {
      type: Array,
      default: _ => []
    }
  },
  watch: {
    // 如果选中权限点数组发生改变,那么就使用setCheckedKeys方法 其参数第一个为选中参数数组
    defaultPermIds() {
      this.$refs.tree.setCheckedKeys(this.defaultPermIds)
    }
  },
  methods: {
    // 取消按钮
    cancelButton() {
      this.$refs.tree.setCheckedKeys([])
      this.$emit('update:dialogVisible', false)
    },

    // 设置权限按钮
    setRolesBtn() {
      this.$emit('confirmEV', this.$refs.tree.getCheckedKeys())
      this.$refs.tree.setCheckedKeys([])
      this.$emit('update:dialogVisible', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  margin-top: 30px;
}
</style>
